package com.sky.mapper;

import com.github.pagehelper.Page;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;


@Mapper
public interface OrderMapper {


    void insert(Orders orders);


    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);


    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);


    @Select("select * from orders where id=#{id} ")
    Orders getById(Long id);

    /**
     * 根据订单id删除订单
     *
     * @param id
     */
    @Delete("delete from orders where id=#{id} ")
    void deleteById(Long id);

    @Select("select count(*) from orders where status=#{status}")
    Integer countByToBeConfirmed(Integer status);

    Integer countByConfirmed(Integer status);

    Integer countByDeliveryInProgress(Integer status);

    /**
     * 根据订单状态和下单时间
     * 查询超时订单
     *
     * @param pendingPayment
     * @param time
     * @return
     */
    @Select("select * from orders where status=#{pendingPayment} and order_Time<#{time} ")
    List<Orders> getByStatusAndOrderTimeLT(Integer pendingPayment, LocalDateTime time);

    /**
     * 根据动态条件 Map 来统计营业额
     *
     * @param map
     * @return
     */
    Double sumByMap(Map map);

    Integer countMap(Map map);

    /**
     * 查询指定时间内的销量前10
     */
    List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
}